package com.wanmait.server.controller;

import com.wanmait.common.response.BaseResponse;
import com.wanmait.common.response.StatusCode;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
   *@Author 蝶影
   *@Date 2020/12/8  19:50
   *@Version 1.0
**/
@Controller
public class LoginController extends AbstractController {

    /**
     * 点击登录，对用户名和密码进行验证
     * @Author 蝶影
     * @Date 2020/12/8  20:12
     * @Version 1.0
     **/
    @RequestMapping("loginVerification")
    @ResponseBody
    public BaseResponse<String> loginVerification(String username, String password) {
        log.info("用户名{}，密码{}", username, password);

        try {
            //登陆
            Subject subject = SecurityUtils.getSubject();
            if(!subject.isAuthenticated()){
                UsernamePasswordToken token = new UsernamePasswordToken(username,password);
                subject.login(token);
            }

        } catch (Exception e) {
           return new BaseResponse<String>(StatusCode.Fail.getCode(),e.getMessage());
        }

        return new BaseResponse<String>(StatusCode.Success);
    }

















}
